home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Tool Chest / Development Tools & Languages / HyperCard Related / APDA HyperCard Toolkits / HyperCard Video Toolkit 2.0 / HVT #2 / Advanced Material / Video Sources / VideoUtil.inc < prev    next >
Encoding:
Text File  |  1995-02-07  |  3.4 KB  |  131 lines  |  [TEXT/MPS ]

  1. {        Miscellaneous routines used with the video XCMDs.
  2.  
  3.     This file in included in the other video XCMD source code files -- i.e., it is not compiled and
  4.     linked separately. It contains a variety of useful utility routines.
  5.  
  6.     Copyright © 1987,88 Apple Computer, Inc.
  7.  
  8.     Initial coding 9/87 by Harry Chesley.
  9. }
  10.  
  11. procedure GetStrGlobal(name: str255; var glob: str255);
  12.     { Set glob to the global string specified by name. }
  13.  
  14.     var globHand: Handle;
  15.  
  16.     begin
  17.         globHand := GetGlobal(name);
  18.         if globHand = nil then glob := ''
  19.         else
  20.             begin
  21.                 ZeroToPas(globHand^,glob);
  22.                 DisposHandle(globHand);
  23.             end;
  24.     end;
  25.  
  26. function GetLongGlobal(name: str255): longInt;
  27.     { Return the global string specified by name, interpreted as a long integer. }
  28.  
  29.     var globStr: str255;
  30.  
  31.     begin
  32.         GetStrGlobal(name,globStr);
  33.         GetLongGlobal := StrToLong(globStr);
  34.     end;
  35.  
  36. procedure SetStrGlobal(name: str255; glob: str255);
  37.     { Set the global string specified by name to glob. }
  38.  
  39.     var globHand: Handle;
  40.  
  41.     begin
  42.         globHand := PasToZero(glob);
  43.         SetGlobal(name,globHand);
  44.         DisposHandle(globHand);
  45.     end;
  46.  
  47. procedure SetLongGlobal(name: str255; globLong: longInt);
  48.     {Set the global string specified by name to a string that represents the number in globLong. }
  49.  
  50.     var globStr: str31;
  51.  
  52.     begin
  53.         globStr := LongToStr(globLong);
  54.         SetStrGlobal(name,globStr);
  55.     end;
  56.  
  57. procedure GetStrParm(n: integer; var str: str255);
  58.     { Get the nth parameter into str. }
  59.  
  60.     begin
  61.         ZeroToPas(paramPtr^.params[n]^,str);
  62.     end;
  63.  
  64. function GetLongParm(n: integer): longInt;
  65.     { Return the nth parameter string, interpreted as a long integer. }
  66.  
  67.     var str: str255;
  68.  
  69.     begin
  70.         ZeroToPas(paramPtr^.params[n]^,str);
  71.         GetLongParm := StrToNum(str);
  72.     end;
  73.  
  74. function EvalStr(expr: str255): str255;
  75.     { Evaluate the expression expr and return the resulting string. }
  76.  
  77.     var theResultHandle: Handle;
  78.         theResultString: str255;
  79.  
  80.     begin
  81.         { Evaluate the expression into a zero-terminated handle. }
  82.         theResultHandle := EvalExpr(expr);
  83.         { Check for user abort (HyperCard returns 1 if the user typed command-period; this is
  84.             an undocuments but very usefull feature). }
  85.         if paramPtr^.result <> xresSucc then Fail('abort');
  86.         { Check for nil return. }
  87.         if theResultHandle <> nil then
  88.             begin
  89.                 { If not nil, convert it to a Pascal string. }
  90.                 ZeroToPas(theResultHandle^,theResultString);
  91.                 DisposHandle(theResultHandle);
  92.                 EvalStr := theResultString;
  93.             end
  94.         { If nil, return an empty string. }
  95.         else EvalStr := '';
  96.     end;
  97.  
  98. procedure EvalAndDispose(expr: str255);
  99.     { Evaluate the expression expr and throw away the result -- useful when you're only interested in the side-effects. }
  100.  
  101.     var theResultHandle: Handle;
  102.  
  103.     begin
  104.         theResultHandle := EvalExpr(expr);
  105.         { Check for user abort (HyperCard returns 1 if the user typed command-period; this is
  106.             an undocuments but very usefull feature). }
  107.         if paramPtr^.result <> xresSucc then Fail('abort');
  108.         if theResultHandle <> nil then DisposHandle(theResultHandle);
  109.     end;
  110.  
  111. procedure videoCmd(cmd, parms: str255);
  112.     { Send a command to the currently selected video driver. }
  113.  
  114.     var str: str255;
  115.  
  116.     begin
  117.         GetStrGlobal('typeOfVideo',str);
  118.         if str <> '' then EvalAndDispose(Concat('vidDrvr',str,'("',cmd,'",',parms,')'));
  119.     end;
  120.  
  121. function videoFunc(cmd, parms: str255): str255;
  122.     { Call a function in the currently selected video driver. }
  123.  
  124.     var str: str255;
  125.  
  126.     begin
  127.         GetStrGlobal('typeOfVideo',str);
  128.         if str <> '' then videoFunc := EvalStr(Concat('vidDrvr',str,'("',cmd,'",',parms,')'))
  129.         else videoFunc := '';
  130.     end;
  131.